package com.heima.kafka.boot.contorller;

import com.alibaba.fastjson.JSON;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.awt.image.Kernel;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/producer")
public class ProducerController {

    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;

    @GetMapping("/send")
    public String sendMessage(){
        Map map = new HashMap();
        map.put("name","二狗子");
        map.put("sex","男");
        map.put("age","13");

        kafkaTemplate.send("boot-topic", JSON.toJSONString(map));
        return "发送成功";
    }
}
